<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="工单编号" prop="workOrderCode">
        <el-input
          v-model="queryParams.workOrderCode"
          placeholder="请输入工单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户编码" prop="clientCode">
        <el-input
          v-model="queryParams.clientCode"
          placeholder="请输入客户编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['as:zero:add']"
        >新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="zeroList" border>
      <el-table-column label="工单编号" align="center" prop="workOrderCode" />
      <el-table-column label="工单类型" align="center" prop="workOrderType" />
      <el-table-column label="客户名称" align="center" prop="clientName" />
      <el-table-column label="工单状态" align="center" prop="workOrderStatus">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.workOrderStatus === '草稿'" type="info">草稿</el-tag>
          <el-tag v-if="scope.row.workOrderStatus === '已提交'" type="warning">已提交</el-tag>
          <el-tag v-if="scope.row.workOrderStatus === '已处置'" type="danger">已处置</el-tag>
          <el-tag v-if="scope.row.workOrderStatus === '已整改'">已整改</el-tag>
          <el-tag v-if="scope.row.workOrderStatus === '已完成'" type="success">已完成</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="联系人" align="center" prop="person" />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleView(scope.row)"
              v-hasPermi="['as:zero:query']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['as:zero:edit']"
            v-if="scope.row.workOrderStatus === '草稿'"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['as:zero:remove']"
            v-if="scope.row.workOrderStatus === '草稿'"
          >删除</el-button>
          <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleDisposition(scope.row)"
              v-hasPermi="['as:zero:disposition']"
              v-if="scope.row.workOrderStatus === '已提交'"
          >异议处置</el-button>
          <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleRectify(scope.row)"
              v-hasPermi="['as:zero:rectify']"
              v-if="scope.row.workOrderStatus === '已处置'"
          >整改</el-button>
          <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleCheck(scope.row)"
              v-hasPermi="['as:zero:check']"
              v-if="scope.row.workOrderStatus === '已整改'"
          >验证</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改零公里工单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">

        <el-card style="border-radius: 10px">
          <el-row>
            <el-col :span="8">
              <el-form-item label="工单编号" prop="workOrderCode">
                <el-input v-model="form.workOrderCode" placeholder="请输入工单编号" readonly />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item  label-width="80">
                <el-switch v-model="autoGenFlag"
                           active-color="#13ce66"
                           active-text="自动生成"
                           @change="handleAutoGenChange(autoGenFlag)"
                           v-if="optType === 'add' && form.workOrderStatus === '草稿'"
                >
                </el-switch>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="8">
              <el-form-item label="客户ID" prop="clientId" style="display: none;">
                <el-input v-model="form.clientId" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户编号" prop="clientCode" style="display: none;">
                <el-input v-model="form.clientCode" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户简称" prop="clientNick" style="display: none;">
                <el-input v-model="form.clientNick" placeholder="请输入客户简称" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户名称" prop="clientName">
                <el-input v-model="form.clientName" placeholder="请选择客户" readonly>
                  <el-button
                    slot="append"
                    @click="handleSelectClient"
                    icon="el-icon-search"
                    v-if="optType === 'add'"
                  >
                  </el-button>
                </el-input>
                <ClientSelect ref="clientSelect" @onSelected="onClientSelected" > </ClientSelect>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户地址" prop="clientAddress">
                <el-input v-model="form.clientAddress" readonly />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="联系人" prop="person">
                <el-input
                    v-model="form.person"
                    placeholder="请输入联系人"
                    :readonly="optType !== 'add' && optType !== 'update'"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="电话" prop="phone">
                <el-input
                    v-model="form.phone"
                    placeholder="请输入电话"
                    :readonly="optType !== 'add' && optType !== 'update'"/>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="处置部门ID" prop="disposalDeptId" style="display: none;">
                <el-input v-model="form.disposalDeptId" placeholder="请输入处置部门ID" />
              </el-form-item>
              <el-form-item label="异议处置部门" prop="disposalDept">
                <treeselect
                  v-model="deptList"
                  :options="deptOptions"
                  :show-count="true"
                  placeholder="请选择异议处置部门"
                  multiple
                  :disabled="optType !== 'add' && optType !== 'update'"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <div v-if="form.id != null">
            <ZeroLine
                ref="zeroLine"
                :zeroId="form.id"
                :optType="optType"
            >
            </ZeroLine>
          </div>

          <el-row>
            <el-col :span="24">
              <el-form-item label="问题描述" prop="remark">
                <el-input
                    v-model="form.remark"
                    type="textarea"
                    placeholder="请输入内容"
                    :readonly="optType !== 'add' && optType !== 'update'"/>
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item label="附件" prop="url">
            <FileUpload
              :limit="100"
              :fileSize="100"
              :fileType="fileType"
              :value="fileList"
              :optType="optType"
              :isShowTip="false"
              @onUploaded="handleUploaded"
              @onRemoved="handleRemoved"
            >
            </FileUpload>
          </el-form-item>
        </el-card>

        <el-divider v-if="form.workOrderStatus !== '草稿'" content-position="center">处置信息</el-divider>

        <el-card style="border-radius: 10px; height: 350px;" v-if="form.workOrderStatus !== '草稿'">
          <el-row>
            <el-col :span="12">
              <el-form-item label="处置人" prop="disposalPerson">
                <el-input v-model="form.disposalPerson" placeholder="请输入处置人" readonly>
                  <el-button
                      slot="append"
                      icon="el-icon-search"
                      @click="handleSelectUser"
                      v-if="optType === 'disposition'"
                  ></el-button>
                </el-input>
                <UserSelect ref="userSelect" @onSelected="onUserSelected" ></UserSelect>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="处置时间" prop="disposalTime">
                <el-date-picker
                    clearable
                    v-model="form.disposalTime"
                    type="datetime"
                    placeholder="请选择处置时间"
                    :disabled="optType !== 'disposition'"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="处置费用" prop="disposalPrice">
                <el-input-number
                    v-model="form.disposalPrice"
                    :min="0"
                    :precision="2"
                    placeholder="请输入处置费用"
                    :disabled="optType !== 'disposition'"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="处置方式" prop="disposalWay">
                <el-select v-model="form.disposalWay" placeholder="请选择处置方式" :disabled="optType !== 'disposition'">
                  <el-option
                      v-for="item in disposalWayOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                  label="处罚金额"
                  prop="disposalAmount"
                  v-if="form.disposalWay === 'rectify+punish' || form.disposalWay === 'punish'">
                <el-input-number
                    v-model="form.disposalAmount"
                    :min="0"
                    :precision="2"
                    placeholder="请输入处罚金额"
                    :disabled="optType !== 'disposition'"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="整改部门ID" prop="rectifyDeptId" style="display: none;">
                <el-input v-model="form.rectifyDeptId" placeholder="请输入整改部门ID" />
              </el-form-item>
              <el-form-item
                  label="整改部门"
                  prop="rectifyDept"
                  v-if="form.disposalWay === 'rectify' || form.disposalWay === 'rectify+punish'"
              >
                <treeselect
                    ref="treeselect"
                    :key="'treeselect-' + form.disposalWay"
                    v-model="rectifyList"
                    :options="deptOptions"
                    :show-count="true"
                    placeholder="请选择异议处置部门"
                    multiple
                    :disabled="optType !== 'disposition'"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item
                  label="处罚结果"
                  prop="disposalResult"
                  v-if="form.disposalWay === 'rectify+punish' || form.disposalWay === 'punish'">
                <el-input
                    v-model="form.disposalResult"
                    type="textarea"
                    placeholder="请输入内容"
                    :readonly="optType !== 'disposition'"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-divider
            content-position="center"
            v-if="form.workOrderStatus !== '草稿' && form.workOrderStatus !== '已提交' && form.disposalWay !== 'punish'">
          整改信息
        </el-divider>

        <el-card
            style="border-radius: 10px;"
            v-if="form.workOrderStatus !== '草稿' && form.workOrderStatus !== '已提交' && form.disposalWay !== 'punish'">
          <el-row>
            <el-col :span="12">
              <el-form-item label="整改负责人" prop="rectifyPerson" >
                <el-input v-model="form.rectifyPerson" placeholder="请输入整改负责人" readonly>
                  <el-button
                      slot="append"
                      icon="el-icon-search"
                      @click="handleSelectUser"
                      v-if="optType === 'rectify'"
                  ></el-button>
                </el-input>
                <UserSelect ref="userSelect" @onSelected="onUserSelectedZg" ></UserSelect>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="整改时间" prop="rectifyTime">
                <el-date-picker
                    clearable
                    v-model="form.rectifyTime"
                    type="datetime"
                    placeholder="请选择整改时间"
                    :disabled="optType !== 'rectify'">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="整改结果" prop="rectifyResult">
                <el-input
                    v-model="form.rectifyResult"
                    type="textarea"
                    placeholder="请输入内容"
                    :readonly="optType !== 'rectify'"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-divider
            content-position="center"
            v-if="form.workOrderStatus !== '草稿' && form.workOrderStatus !== '已提交' && form.workOrderStatus !== '已处置'
            && form.disposalWay !== 'punish'">验证信息
        </el-divider>

        <el-card
            style="border-radius: 10px;"
            v-if="form.workOrderStatus !== '草稿' && form.workOrderStatus !== '已提交' && form.workOrderStatus !== '已处置'
            && form.disposalWay !== 'punish'">
          <el-row>
            <el-col :span="12">
              <el-form-item label="验证人" prop="checkPerson">
                <el-input v-model="form.checkPerson" placeholder="请输入验证人" readonly>
                  <el-button
                      slot="append"
                      icon="el-icon-search"
                      @click="handleSelectUser"
                      v-if="optType === 'check'"
                  ></el-button>
                </el-input>
                <UserSelect ref="userSelect" @onSelected="onUserSelectedYz" ></UserSelect>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="验证时间" prop="checkTime">
                <el-date-picker
                    clearable
                    v-model="form.checkTime"
                    type="datetime"
                    placeholder="请选择验证时间"
                    :disabled="optType !== 'check'">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="验证结果" prop="checkResult">
                <el-input
                    v-model="form.checkResult"
                    type="textarea"
                    placeholder="请输入内容"
                    :readonly="optType !== 'check'"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="success" @click="handleSubmit" v-if="optType === 'update'">提 交</el-button>
        <el-button type="success" @click="handleDispositionSubmit" v-if="optType === 'disposition'">处 置</el-button>
        <el-button type="primary" @click="handleRectifySubmit" v-if="optType === 'rectify'">整 改</el-button>
        <el-button type="primary" @click="handleCheckSubmit" v-if="optType === 'check'">验 证</el-button>
        <el-button type="primary" @click="submitForm" v-if="optType !== 'view'">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listZero, getZero, delZero, addZero, updateZero } from "@/api/mes/as/zero";
import { genCode } from "@/api/system/autocode/rule";
import ClientSelect from "@/components/clientSelect/single.vue";
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import ZeroLine from "./line.vue";
import FileUpload from "./upload.vue";
import { getUserProfile } from "@/api/system/user";
import UserSelect from "@/components/userSelect/single.vue";


export default {
  name: "Zero",
  components: {
    Treeselect,
    ClientSelect,
    ZeroLine,
    FileUpload,
    UserSelect,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 零公里工单表格数据
      zeroList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workOrderCode: null,
        workOrderType: null,
        clientId: null,
        clientCode: null,
        clientName: null,
        clientNick: null,
        clientAddress: null,
        workOrderStatus: null,
        person: null,
        phone: null,
        disposalDeptId: null,
        disposalDept: null,
        url: null,
        disposalPerson: null,
        disposalTime: null,
        disposalPrice: null,
        disposalWay: null,
        disposalAmount: null,
        disposalResult: null,
        rectifyDeptId: null,
        rectifyDept: null,
        rectifyPerson: null,
        rectifyTime: null,
        rectifyResult: null,
        checkPerson: null,
        checkTime: null,
        checkResult: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        workOrderCode: [
          { required: true, message: "工单编号不能为空", trigger: "blur" }
        ],
        clientName: [
          { required: true, message: "客户名称不能为空", trigger: "blur" }
        ],

      },
      //自动生成编码
      autoGenFlag:false,
      // 标识
      optType: undefined,
      // 部门树选项
      deptOptions: undefined,
      // 上传文件类型
      fileType: [
        // 文档类
        "pdf", "doc", "docx", "xls", "xlsx",
        // 图片类
        "jpg", "jpeg", "png", "gif", "bmp",
        // 视频类
        "mp4", "avi", "rmvb", "mkv", "mov",
        // 压缩文件类
        "zip", "rar", "7z", "tar", "gz"
      ],
      // 上传文件列表
      fileList: [],
      // 部门数组
      deptList: [],
      // 处置方式数组
      disposalWayOptions: [
        {label: "整改", value: "rectify"},
        {label: "处罚", value: "punish"},
        {label: "整改+处罚", value: "rectify+punish"},
      ],
      // 当前登录用户
      user: null,
      // 整改部门
      rectifyList: [],
    };
  },
  created() {
    this.getList();
    this.getTreeselect();
    this.getUserProfile();
  },
  methods: {
    /** 查询零公里工单列表 */
    getList() {
      this.loading = true;
      listZero(this.queryParams).then(response => {
        this.zeroList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        workOrderCode: null,
        workOrderType: '零公里工单',
        clientId: null,
        clientCode: null,
        clientName: null,
        clientNick: null,
        clientAddress: null,
        workOrderStatus: "草稿",
        person: null,
        phone: null,
        disposalDeptId: null,
        disposalDept: null,
        remark: null,
        url: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        disposalPerson: null,
        disposalTime: null,
        disposalPrice: null,
        disposalWay: null,
        disposalAmount: null,
        disposalResult: null,
        rectifyDeptId: null,
        rectifyDept: null,
        rectifyPerson: null,
        rectifyTime: null,
        rectifyResult: null,
        checkPerson: null,
        checkTime: null,
        checkResult: null
      };
      this.deptList = [];
      this.rectifyList = [];
      this.fileList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getTreeselect();
      this.open = true;
      this.title = "添加零公里工单";
      this.optType = 'add';
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getTreeselect();
      const id = row.id || this.ids
      getZero(id).then(response => {
        this.form = response.data;
        response.data.url === null ? this.fileList = [] : this.fileList = response.data.url.split(',');
        if (response.data.disposalDept) {
          this.deptList = response.data.disposalDept.split(',');
        }
        if (response.data.rectifyDept) {
          this.rectifyList = response.data.rectifyDept.split(',');
        }
        this.open = true;
        this.title = "修改零公里工单";
        this.optType = 'update'
      });
    },
    /** 详情按钮操作 */
    handleView(row) {
      this.reset();
      const id = row.id || this.ids;
      getZero(id).then(response => {
        this.form = response.data;
        response.data.url === null ? this.fileList = [] : this.fileList = response.data.url.split(',');
        if (response.data.disposalDept) {
          this.deptList = response.data.disposalDept.split(',');
        }
        if (response.data.rectifyDept) {
          this.rectifyList = response.data.rectifyDept.split(',');
        }
        this.open = true;
        this.title = "查看零公里工单";
        this.optType = 'view'
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.disposalDept = this.deptList.join(',');
          this.form.rectifyDept = this.rectifyList.join(',');
          if (this.form.id != null) {
            updateZero(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addZero(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除零公里工单编号为"' + ids + '"的数据项？').then(function() {
        return delZero(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('as/zero/export', {
        ...this.queryParams
      }, `zero_${new Date().getTime()}.xlsx`)
    },
    //自动生成编码
    handleAutoGenChange(autoGenFlag){
      if(autoGenFlag){
        genCode('ZERO_WORK_ORDER_CODE').then(response =>{
          this.form.workOrderCode = response;
        });
      }else{
        this.form.workOrderCode = null;
      }
    },
    handleSelectClient(){
      this.$refs.clientSelect.showFlag = true;
    },
    //客户选择弹出框
    onClientSelected(obj){
      if(obj !== undefined && obj !== null){
        this.form.clientId = obj.clientId;
        this.form.clientCode = obj.clientCode;
        this.form.clientName = obj.clientName;
        this.form.clientAddress = obj.address;
      }
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
        console.log('部门树数据:', this.deptOptions);
      });
    },
    // 上传成功回调
    handleUploaded(data) {
      this.form.url = data;
    },
    // 删除成功回调
    handleRemoved(data) {
      this.form.url = data;
    },
    // 提交
    handleSubmit() {
      this.form.workOrderStatus = '已提交';
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateZero(this.form).then(response => {
            this.$modal.msgSuccess("提交成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    // 处置
    handleDisposition(row) {
      this.reset();
      this.getTreeselect();
      const id = row.id || this.ids
      getZero(id).then(response => {
        this.form = response.data;
        response.data.url === null ? this.fileList = [] : this.fileList = response.data.url.split(',');
        if (response.data.disposalDept) {
          this.deptList = response.data.disposalDept.split(',');
        }
        if (response.data.rectifyDept) {
          this.rectifyList = response.data.rectifyDept.split(',');
        }
        this.form.disposalPerson = this.user.nickName
        this.open = true;
        this.title = "处置零公里工单";
        this.optType = 'disposition'
      });
    },
    // 获取当前用户
    getUserProfile() {
      getUserProfile().then(response => {
        this.user = response.data;
      });
    },
    handleSelectUser(){
      this.$refs.userSelect.showFlag = true;
    },
    // 用户选择弹出框
    onUserSelected(obj){
      if(obj !== undefined && obj !== null){
        this.form.disposalPerson = obj.nickName;
      }
    },
    // 处置
    handleDispositionSubmit() {
      let way = this.form.disposalWay;
      if (way === 'punish') {
        this.form.workOrderStatus = '已完成'
      }else {
        this.form.workOrderStatus = '已处置'
      }
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateZero(this.form).then(response => {
            this.$modal.msgSuccess("提交成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    // 整改点击
    handleRectify(row) {
      this.reset();
      this.getTreeselect();
      const id = row.id || this.ids
      getZero(id).then(response => {
        this.form = response.data;
        response.data.url === null ? this.fileList = [] : this.fileList = response.data.url.split(',');
        if (response.data.disposalDept) {
          this.deptList = response.data.disposalDept.split(',');
        }
        if (response.data.rectifyDept) {
          this.rectifyList = response.data.rectifyDept.split(',');
        }
        this.form.rectifyPerson = this.user.nickName
        this.open = true;
        this.title = "整改零公里工单";
        this.optType = 'rectify'
      });
    },
    // 整改负责人选择弹出框
    onUserSelectedZg(obj) {
      if(obj !== undefined && obj !== null){
        this.form.rectifyPerson = obj.nickName;
      }
    },
    // 整改
    handleRectifySubmit() {
      this.form.workOrderStatus = '已整改';
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateZero(this.form).then(response => {
            this.$modal.msgSuccess("提交成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    // 验证点击
    handleCheck(row) {
      this.reset();
      this.getTreeselect();
      const id = row.id || this.ids
      getZero(id).then(response => {
        this.form = response.data;
        response.data.url === null ? this.fileList = [] : this.fileList = response.data.url.split(',');
        if (response.data.disposalDept) {
          this.deptList = response.data.disposalDept.split(',');
        }
        if (response.data.rectifyDept) {
          this.rectifyList = response.data.rectifyDept.split(',');
        }
        this.form.checkPerson = this.user.nickName
        this.open = true;
        this.title = "验证零公里工单";
        this.optType = 'check'
      });
    },
    // 验证人选择弹出框
    onUserSelectedYz(obj) {
      if(obj !== undefined && obj !== null){
        this.form.checkPerson = obj.nickName;
      }
    },
    // 验证
    handleCheckSubmit() {
      this.form.workOrderStatus = '已完成';
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateZero(this.form).then(response => {
            this.$modal.msgSuccess("提交成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },

  }
};
</script>
